package fr.norsys.mapper.console.web;

import uk.ltd.getahead.dwr.ExecutionContext;
import fr.norsys.mapper.console.model.Application;
import fr.norsys.mapper.console.model.ConsoleCst;
import fr.norsys.mapper.console.model.Variable;
import fr.norsys.mapper.console.service.ApplicationService;
import fr.norsys.mapper.console.service.VariableService;

public class VariableServiceDWR {
	private VariableService variableService;
	private ApplicationService applicationService;
	public VariableService getVariableService() {
		return variableService;
	}
	public void setVariableService(VariableService variableService) {
		this.variableService = variableService;
	}
	public ApplicationService getApplicationService() {
		return applicationService;
	}
	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}
	/**
	 * Save a new variable 
	 * @param variable
	 * @return boolean
	 */
	public boolean save(Variable variable) throws Exception {
		Application currentAppli = (Application) ExecutionContext.get().getSession().getAttribute(
				ConsoleCst.CURRENT_APPLICATION);
		boolean res = variableService.save(variable,currentAppli.getVariables());
		ExecutionContext.get().getSession().setAttribute(ConsoleCst.IS_APPLICATION_MODIFIED,ConsoleCst.APPLICATION_MODIFIED);
		return res;
	}
}